<?php
/**********************************************************************
    Copyright (C) FrontAccounting, LLC.
	Released under the terms of the GNU General Public License, GPL, 
	as published by the Free Software Foundation, either version 3 
	of the License, or (at your option) any later version.
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
$page_security = $_POST['PARAM_0'] == $_POST['PARAM_1'] ?
	'SA_SALESTRANSVIEW' : 'SA_SALESBULKREP';
// ----------------------------------------------------------------
// $ Revision:	2.0 $
// Creator:	Joe Hunt
// date_:	2005-05-19
// Title:	Print Sales Orders
// ----------------------------------------------------------------
$path_to_root="..";

/*include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/sales/includes/sales_db.inc");
include_once($path_to_root . "/taxes/tax_calc.inc");
*/
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/date_functions.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/data_checks.inc");
include_once($path_to_root . "/sales/includes/sales_db.inc");
include_once($path_to_root . "/taxes/tax_calc.inc");
include_once($path_to_root . "/reporting/includes/reporting.inc");
include($path_to_root . "/pittycash/includes/db/pittycash_db.inc");


print_sales_orders();

$print_as_quote = 0;

function print_sales_orders()
{
	global $path_to_root, $print_as_quote;

	include_once($path_to_root . "/reporting/includes/pdf_report.inc");

	$from = $_POST['PARAM_0'];
	$to = $_POST['PARAM_1'];
	$currency = $_POST['PARAM_2'];
	$email = $_POST['PARAM_3'];
	$print_as_quote = $_POST['PARAM_4'];
	$comments = $_POST['PARAM_5'];

	if ($from == null)
		$from = 0;
	if ($to == null)
		$to = 0;
	$dec = user_price_dec();

	//$cols = array(1,4, 60, 225, 300, 325, 385, 450, 515);
     $cols = array(4, 100, 600);

	// $headers in doctext.inc
	$aligns = array('left',	'left');
     
	$params = array('comments' => $comments);

	$cur = get_company_Pref('curr_default');

	if ($email == 0)
	{
		if ($print_as_quote == 0)
		$rep = new FrontReport(_("SALES ORDER"), "SalesOrderBulk", user_pagesize());			
		else
			$rep = new FrontReport(_("QUOTE"), "QuoteBulk", user_pagesize());
		$rep->SetHeaderType('Header8');
		$rep->currency = $cur;
		$rep->Font();
		$rep->Info($params, $cols, null, $aligns);
		//$rep->Info($params, null, null, $aligns);
	}

	for ($i = $from; $i <= $to; $i++)
	{
		//$myrow = get_sales_order_header($i, ST_SALESORDER);
		  $myrow = get_kas_bon($i, ST_KASBON);
		//$baccount = get_default_bank_account($myrow['curr_code']);
		//$params['bankaccount'] = $baccount['id'];
		//$branch = get_branch($myrow["branch_code"]);
		if ($email == 1)
		{
			$rep = new FrontReport("", "", user_pagesize());
			$rep->SetHeaderType('Header8');
			$rep->currency = $cur;
			$rep->Font();
			if ($print_as_quote == 1)
			{
				$rep->title = _('QUOTE');
				$rep->filename = "Quote" . $i . ".pdf";
			}
			else
			{
				$rep->title = _("SALES ORDER");
				$rep->filename = "SalesOrder" . $i . ".pdf";
			}
			$rep->Info($params, $cols, null, $aligns);
			
		}
		else
		$rep->title = ($print_as_quote==1 ? _("QUOTE") : _("SALES ORDER"));
		//$contacts = get_branch_contacts($branch['branch_code'], 'order', $branch['debtor_no']);
		//$tmp=array('coba' => 'isicoba');
		//$myrow=array_merge($myrow,$tmp);
		$rep->SetCommonData($myrow, $branch, $myrow, $baccount, ST_KASBON, $contacts);
		$rep->NewPage();

		
		$items = $prices = array();


		
		   	$rep->TextCol(0, 1,	 _("Dibayarkan kepada :"), -2);
			$rep->TextCol(1, 2,	$myrow['empname'], -2);
			$rep->NewLine();			
			$rep->TextCol(0, 1,	 _("Uang sejumlah :"), -2);
			$rep->TextCol(1, 2,	price_decimal_format($myrow['amount'],$dec2) , -2);
			$rep->NewLine(4);
			
			$rep->TextCol(0, 1,	 _("Untuk :"), -2);
			$rep->TextCol(1, 2,	$myrow['note'], -2);
	
			
	}
	if ($email == 0)
		$rep->End();
		
}

?>